-
MGLStyleLayer
is an abstract base class for style layers. A style layer manages the layout and appearance of content at a specific z-index in a style. AnMGLStyle
object consists of one or moreMGLStyleLayer
objects.Each style layer defined by the style JSON file is represented at runtime by an
MGLStyleLayer
object, which you can use to refine the map’s appearance. You can also add and remove style layers dynamically.Create instances of
MGLBackgroundStyleLayer
and the concrete subclasses ofMGLForegroundStyleLayer
in order to useMGLStyleLayer
‘s properties and methods. You do not create instances ofMGLStyleLayer
directly, and do not create your own subclasses of this class.Do not add
See moreMGLStyleLayer
objects to thestyle
property of aMGLMapView
before-mapView:didFinishLoadingStyle:
is called.Declaration
Objective-C
@interface MGLStyleLayer : NSObject
Swift
class MGLStyleLayer : NSObject
-
MGLForegroundStyleLayer
is an abstract superclass for style layers whose content is defined by anMGLSource
object.Create instances of
See moreMGLRasterStyleLayer
and the concrete subclasses ofMGLVectorStyleLayer
in order to useMGLForegroundStyleLayer
‘s methods. Do not create instances ofMGLForegroundStyleLayer
directly, and do not create your own subclasses of this class.Declaration
Objective-C
@interface MGLForegroundStyleLayer : MGLStyleLayer
Swift
class MGLForegroundStyleLayer : MGLStyleLayer
-
An
MGLBackgroundStyleLayer
is a style layer that covers the entire map. Use a background style layer to configure a color or pattern to show below all other map content. If the style’s other layers use the Mapbox Streets source, the background style layer is responsible for drawing land, whereas the oceans and other bodies of water are drawn byMGLFillStyleLayer
objects.A background style layer is typically the bottommost layer in a style, because it covers the entire map and can occlude any layers below it. You can therefore access it by getting the last item in the
MGLStyle.layers
array.If the background style layer is transparent or omitted from the style, any portion of the map view that does not show another style layer is transparent.
See moreDeclaration
Objective-C
@interface MGLBackgroundStyleLayer : MGLStyleLayer
Swift
class MGLBackgroundStyleLayer : MGLStyleLayer
-
An
MGLRasterStyleLayer
is a style layer that renders raster tiles on the map.Use a raster style layer to configure the color parameters of raster tiles loaded by an
MGLRasterSource
object. For example, you could use a raster style layer to render Mapbox Satellite imagery, a raster tile set uploaded to Mapbox Studio, or a raster map authored in TileMill, the classic Mapbox Editor, or Mapbox Studio Classic.You can access an existing raster style layer using the
-[MGLStyle layerWithIdentifier:]
method if you know its identifier; otherwise, find it using theMGLStyle.layers
property. You can also create a new raster style layer and add it to the style using a method such as-[MGLStyle addLayer:]
.Example
See morelet layer = MGLRasterStyleLayer(identifier: "clouds", source: source) layer.rasterOpacity = MGLStyleValue(rawValue: 0.5) mapView.style?.addLayer(layer)
Declaration
Objective-C
@interface MGLRasterStyleLayer : MGLForegroundStyleLayer
Swift
class MGLRasterStyleLayer : MGLForegroundStyleLayer
-
MGLVectorStyleLayer
is an abstract superclass for style layers whose content is defined by anMGLShapeSource
orMGLVectorSource
object.Create instances of
See moreMGLCircleStyleLayer
,MGLFillStyleLayer
,MGLFillExtrusionStyleLayer
,MGLLineStyleLayer
, andMGLSymbolStyleLayer
in order to useMGLVectorStyleLayer
‘s properties and methods. Do not create instances ofMGLVectorStyleLayer
directly, and do not create your own subclasses of this class.Declaration
Objective-C
@interface MGLVectorStyleLayer : MGLForegroundStyleLayer
Swift
class MGLVectorStyleLayer : MGLForegroundStyleLayer
-
An
MGLCircleStyleLayer
is a style layer that renders one or more filled circles on the map.Use a circle style layer to configure the visual appearance of point or point collection features in vector tiles loaded by an
MGLVectorSource
object orMGLPointAnnotation
,MGLPointFeature
,MGLPointCollection
, orMGLPointCollectionFeature
instances in anMGLShapeSource
object.A circle style layer renders circles whose radii are measured in screen units. To display circles on the map whose radii correspond to real-world distances, use many-sided regular polygons and configure their appearance using an
MGLFillStyleLayer
object.You can access an existing circle style layer using the
-[MGLStyle layerWithIdentifier:]
method if you know its identifier; otherwise, find it using theMGLStyle.layers
property. You can also create a new circle style layer and add it to the style using a method such as-[MGLStyle addLayer:]
.Example
See morelet layer = MGLCircleStyleLayer(identifier: "circles", source: population) layer.sourceLayerIdentifier = "population" layer.circleColor = MGLStyleValue(rawValue: .green) layer.circleRadius = MGLStyleValue(interpolationMode: .exponential, cameraStops: [12: MGLStyleValue(rawValue: 2), 22: MGLStyleValue(rawValue: 180)], options: [.interpolationBase: 1.75]) layer.circleOpacity = MGLStyleValue(rawValue: 0.7) layer.predicate = NSPredicate(format: "%K == %@", "marital-status", "married") mapView.style?.addLayer(layer)
Declaration
Objective-C
@interface MGLCircleStyleLayer : MGLVectorStyleLayer
Swift
class MGLCircleStyleLayer : MGLVectorStyleLayer
-
An
MGLFillStyleLayer
is a style layer that renders one or more filled (and optionally stroked) polygons on the map.Use a fill style layer to configure the visual appearance of polygon or multipolygon features in vector tiles loaded by an
MGLVectorSource
object orMGLPolygon
,MGLPolygonFeature
,MGLMultiPolygon
, orMGLMultiPolygonFeature
instances in anMGLShapeSource
object.You can access an existing fill style layer using the
-[MGLStyle layerWithIdentifier:]
method if you know its identifier; otherwise, find it using theMGLStyle.layers
property. You can also create a new fill style layer and add it to the style using a method such as-[MGLStyle addLayer:]
.Example
See morelet layer = MGLFillStyleLayer(identifier: "parks", source: parks) layer.sourceLayerIdentifier = "parks" layer.fillColor = MGLStyleValue(rawValue: .green) layer.predicate = NSPredicate(format: "type == %@", "national-park") mapView.style?.addLayer(layer)
Declaration
Objective-C
@interface MGLFillStyleLayer : MGLVectorStyleLayer
Swift
class MGLFillStyleLayer : MGLVectorStyleLayer
-
An
MGLFillExtrusionStyleLayer
is a style layer that renders one or more 3D extruded polygons on the map.Use a fill-extrusion style layer to configure the visual appearance of polygon or multipolygon features in vector tiles loaded by an
MGLVectorSource
object orMGLPolygon
,MGLPolygonFeature
,MGLMultiPolygon
, orMGLMultiPolygonFeature
instances in anMGLShapeSource
object.You can access an existing fill-extrusion style layer using the
-[MGLStyle layerWithIdentifier:]
method if you know its identifier; otherwise, find it using theMGLStyle.layers
property. You can also create a new fill-extrusion style layer and add it to the style using a method such as-[MGLStyle addLayer:]
.Example
See morelet layer = MGLFillExtrusionStyleLayer(identifier: "buildings", source: buildings) layer.sourceLayerIdentifier = "building" layer.fillExtrusionHeight = MGLStyleValue(interpolationMode: .identity, sourceStops: nil, attributeName: "height", options: nil) layer.fillExtrusionBase = MGLStyleValue(interpolationMode: .identity, sourceStops: nil, attributeName: "min_height", options: nil) layer.predicate = NSPredicate(format: "extrude == 'true'") mapView.style?.addLayer(layer)
Declaration
Objective-C
@interface MGLFillExtrusionStyleLayer : MGLVectorStyleLayer
Swift
class MGLFillExtrusionStyleLayer : MGLVectorStyleLayer
-
An
MGLLineStyleLayer
is a style layer that renders one or more stroked polylines on the map.Use a line style layer to configure the visual appearance of polyline or multipolyline features in vector tiles loaded by an
MGLVectorSource
object orMGLPolyline
,MGLPolylineFeature
,MGLMultiPolyline
, orMGLMultiPolylineFeature
instances in anMGLShapeSource
object.You can access an existing line style layer using the
-[MGLStyle layerWithIdentifier:]
method if you know its identifier; otherwise, find it using theMGLStyle.layers
property. You can also create a new line style layer and add it to the style using a method such as-[MGLStyle addLayer:]
.Example
See morelet layer = MGLLineStyleLayer(identifier: "trails-path", source: trails) layer.sourceLayerIdentifier = "trails" layer.lineWidth = MGLStyleValue(interpolationMode: .exponential, cameraStops: [14: MGLStyleValue(rawValue: 2), 18: MGLStyleValue(rawValue: 20)], options: [.interpolationBase: 1.5]) layer.lineColor = MGLStyleValue(rawValue: .brown) layer.lineCap = MGLStyleValue(rawValue: NSValue(mglLineCap: .round)) layer.predicate = NSPredicate(format: "%K == %@", "trail-type", "mountain-biking") mapView.style?.addLayer(layer)
Declaration
Objective-C
@interface MGLLineStyleLayer : MGLVectorStyleLayer
Swift
class MGLLineStyleLayer : MGLVectorStyleLayer
-
An
MGLSymbolStyleLayer
is a style layer that renders icon and text labels at points or along lines on the map.Use a symbol style layer to configure the visual appearance of labels for features in vector tiles loaded by an
MGLVectorSource
object orMGLShape
orMGLFeature
instances in anMGLShapeSource
object.You can access an existing symbol style layer using the
-[MGLStyle layerWithIdentifier:]
method if you know its identifier; otherwise, find it using theMGLStyle.layers
property. You can also create a new symbol style layer and add it to the style using a method such as-[MGLStyle addLayer:]
.Example
See morelet layer = MGLSymbolStyleLayer(identifier: "coffeeshops", source: pois) layer.sourceLayerIdentifier = "pois" layer.iconImageName = MGLStyleValue(rawValue: "coffee") layer.iconScale = MGLStyleValue(rawValue: 0.5) layer.text = MGLStyleValue(rawValue: "{name}") layer.textTranslation = MGLStyleValue(rawValue: NSValue(cgVector: CGVector(dx: 10, dy: 0))) layer.textJustification = MGLStyleValue(rawValue: NSValue(mglTextJustification: .left)) layer.textAnchor = MGLStyleValue(rawValue: NSValue(mglTextAnchor: .left)) layer.predicate = NSPredicate(format: "%K == %@", "venue-type", "coffee") mapView.style?.addLayer(layer)
Declaration
Objective-C
@interface MGLSymbolStyleLayer : MGLVectorStyleLayer
Swift
class MGLSymbolStyleLayer : MGLVectorStyleLayer